export default {
	// 将时间戳转换为年月日时分	y年m月d日h时m分
	// 时间戳为10位需*1000，时间戳为13位的话不需乘1000
	timestampToTime(timestamp) {
		var date = new Date(timestamp)
		var Y = date.getFullYear() + '年'
		var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '月'
		var D = date.getDate() + '日 '
		var h = date.getHours() + ':'
		var m = (date.getMinutes() < 10 ? '0' + (date.getMinutes()) : date.getMinutes())
		// var s = date.getSeconds()
		return Y + M + D + h + m
	},
	
	// 将时间戳转换为年月日	y.m.d
	// 时间戳为10位需*1000，时间戳为13位的话不需乘1000
	timestampToTime2(timestamp) {
		var date = new Date(timestamp)
		var Y = date.getFullYear() + '.'
		var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '.'
		var D = date.getDate()
		return Y + M + D
	},
	
	// 获取当前年月日
	getDate(type) {
		var date = new Date()
		let y = date.getFullYear()
		let m = date.getMonth() + 1
		m < 9 ? m = '0' + m : ''
		let d = date.getDate()
		d < 10 ? d = '0' + d : ''
		switch (type)  {
			case 'y':
				return y
				break
			case 'm':
				return m
				break
			case 'd':
				return d
				break
		}
	},

	// 计算特定时间戳与当前时间的间隔
	calcTime(timestamp) {
		let nowDate = (new Date()).getTime();
		let poorTime = nowDate - timestamp
		let m = poorTime / 60000
		if (m < 60) return parseInt(m) + '分钟前'
		let h = poorTime / 3600000
		if (h < 24) return parseInt(h) + '小时前'
		let d = poorTime / 86400000
		if (d < 365) return parseInt(d) + '天前'
		let month = poorTime / 2678400000
		if (month < 12) return parseInt(month) + '月前'
		let y = poorTime / 977616000000
		return parseInt(y) + '年前'
	},

	// 秒转分
	StoM(ss) {
		let s = parseInt(ss)
		let s2 = ''
		let result = ''
		let m = ''
		if (s < 60) {
			s % 60 < 10 ? s2 = '0' + s % 60 : s2 = s % 60
			result = '00:' + s2
		} else if (s >= 60 && s < 600) {
			m = '0' + Math.floor(s / 60)
			s % 60 < 10 ? s2 = '0' + s % 60 : s2 = s % 60
			result = m + ':' + s2
		} else {
			m = Math.floor(s / 60)
			s % 60 < 10 ? s2 = '0' + s % 60 : s2 = s % 60
			result = m + ':' + s2
		}
		return result
	},

	// 播放量转换
	calcPlayCount(playCount) {
		let t = 0
		if (playCount < 100000) {
			t = playCount
		} else {
			t = parseInt(playCount / 10000) + '万'
		}
		return t
	},

	//获取0-x的随机数
	randomNum() {
		return Math.round(Math.random() * 2)
	}
}
